package com.jeff.android.lab.module.widget.fragment;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

/**
 * @author: dingfeng
 * @date: 2020-02-04
 * @since: 1.0.0
 **/
public abstract class BackFragment extends Fragment {

    BackHandleInterface backHandleInterface;

    public abstract boolean onBackPressed();

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getActivity() instanceof BackHandleInterface) {
            backHandleInterface = (BackHandleInterface) getActivity();
        } else {
            throw new ClassCastException("Hosting Activity must implement BackHandleInterface");
        }
    }

    @Override
    public void onStart() {
        super.onStart();
        backHandleInterface.onSelectedFragment(this);
    }

}
